using MoatFight;

using System;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;

public class TimerAgent : AgentContext<TimerAgent, UFrame.Timer.SaftyTimerCtrl>
{
    public static void Start(float timeSpan)
    {
        Instance.Initialze(0.1f);
    }

    public static void DelySecond(Action action, UFrame.IAlive alive = null)
    {
        if (alive == null)
            Instance.DelyExecute(action, 1);
        else
            Instance.DelyExecuteSafty(alive, action, 1);
    }

    public static void DelyFrame(Action action, UFrame.IAlive alive = null)
    {
        if (alive == null)
            Instance.DelyExecute(action, 0);
        else
            Instance.DelyExecuteSafty(alive, action, 0);
    }

    public static void StopTimer(ref int timer)
    {
        if (timer > 0)
            Instance.StopTimer(timer);
        timer = 0;
    }

    internal static int RegistLoopFrame(Func<bool> callback, UFrame.IAlive alive = null)
    {
        if (alive == null)
            return Instance.RegistLoop(callback, 0);
        else
            return Instance.RegistLoopSafty(alive, callback, 0);
    }
}
